package cl.pucv.trazabilidad_android;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import cl.pucv.trazabilidad_android.R.id;



public class Ventana extends Activity {
	//Constantes para la invocacion del Servicio Web
	private final String NAMESPACE = "http://ws.telemedicina.cl";
//	private final String URL = "http://192.168.2.2:8080/ServiciosTelemedicina/services/Prueba1?wsdl";//Conexion  al servicio web
	private final String URL = "http://192.168.0.103:8080/Telemedicina/services/Login?wsdl";//Conexion  al servicio web
	private final String METHOD_NAME = "login";
	private final String SOAP_ACTION = "http://ws.telemedicina.cl/login";
		
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    public void enviarFormulario(View v){
    	try{
    		
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
 
        EditText txtUsername = (EditText)this.findViewById(R.id.txtUsername);
        EditText txtPass = (EditText)this.findViewById(R.id.txtPass);

        request.addProperty("user", txtUsername.getText().toString());
        request.addProperty("pass", txtPass.getText().toString());
        request.addProperty("tipo", "1");
        
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        HttpTransportSE ht = new HttpTransportSE(URL);
        ht.call(SOAP_ACTION, envelope);

        final  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

        final String str = response.toString();
//        System.out.println("Usuario :"+);
//        System.out.println("Password :"+txtPass.getText().toString());
        System.out.println("SIN ERROR :"+str);
    	}catch(Exception e){
    		System.out.println("LLEGUE! CON ERROR");
    		e.printStackTrace();
    	}
    }
   
    public void onCancelClick(View botton){
    	Intent intent = new Intent();
    	intent.setComponent(new ComponentName(this,Result.class));
    	
    	intent.putExtra("Cancel", "Cancel");
    	startActivity(intent);
    }
}